package com.cfwx.db.jdbc;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JDBCTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PreparedStatement pStmt;
		try {
//			Driver mysqlDriver =(Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
//			String msyUrl = "jdbc:mysql://127.0.0.1:3306/team6?"+"useUnicode=true&characterEncoding=utf-8";
			Driver driver =(Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";	
			Connection conn = DriverManager.getConnection(url,"pmsuserscj", "pmsuser");
//			String sql ="select * from student";
//			Statement sts = conn.createStatement();
//			ResultSet res = sts.executeQuery(sql);
//			while(res.next()){
//				System.out.print(res.getString("SID")+" ");
//				System.out.print(res.getString("SNAME")+" ");
//				System.out.println(res.getString("AGE")+" ");
//			}
//			res.close();
//			sts.close();
//			conn.close();
		
			
			
			//prepareStatement
//			pStmt = conn.prepareStatement("insert into student (SID,SNAME,AGE) values (?,?,?)");
//			pStmt.setInt(1,3);
//			pStmt.setString(2,"ewr");
//			pStmt.setString(3,"99");
//			pStmt.executeUpdate();	
			String psql ="select * from student";
		    pStmt = conn.prepareStatement(psql);
			ResultSet res = pStmt.executeQuery();
			conn.commit();
			while(res.next()){
				System.out.print(res.getString("SID")+" ");
			     System.out.print(res.getString("SNAME")+" ");
				System.out.println(res.getString("AGE")+" ");
			}
			res.close();
			pStmt.close();
			conn.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 	
	
}
		
}		
	
	
	
	


